﻿// =====================================================================
// Math.cs
// by Hushel Roberts
// =====================================================================

using System;
using Microsoft.Xna.Framework;

namespace MathUtil
{
    static public class MathLib
    {
        public const float PI = 3.1415926f;
        public const float ZERO_TOLLERANCE = 0.0001f;

        static public float RadToDeg(float radians)
        {
            return radians * 180/PI;
        }

        static public Vector2 ReflectVector2(Vector2 ray, Vector2 normal)
        {
            normal.Normalize();
            Vector2 reflection = new Vector2();
            reflection = ray - (2 * normal * (Vector2.Dot(ray, normal)));
            return reflection;
        }

        static public Vector2 Transform(Matrix mtx, Vector2 vec)
        {
            Vector3 vec3 = new Vector3(vec.X, vec.Y, 0);
            vec3 = Vector3.Transform(vec3, mtx);
            return new Vector2(vec3.X, vec3.Y);
        }

        static public bool NearZero(Vector2 vec)
        {
            if (vec.Length() < ZERO_TOLLERANCE)
            {
                return true;
            }
            return false;
        }

        static public void ZeroVector2(Vector2 vec)
        {
            vec.X = 0.0f;
            vec.Y = 0.0f;
        }
    }

}
